package com.yc.baseProgram;

import java.util.HashSet;
import java.util.Set;

public class StudentHashCode {

	private String num;
    private String name;

    public StudentHashCode(String num, String name) {
        this.num = num;
        this.name = name;
    }
    
    

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof StudentHashCode) {
            if (((StudentHashCode) obj).num.equals(this.num) 
                    && ((StudentHashCode) obj).name.equals(this.name)) {
                return true;
            }
        }

        return false;
    }



	@Override
    public int hashCode() {
        StringBuilder sb = new StringBuilder();
        sb.append(num);
        sb.append(name);
        char[] charArr = sb.toString().toCharArray();
        int hash = 0;
        for(char c : charArr) {
            hash = hash * 131 + c;
        }
        return hash;
    }

    public static void main(String[] args) {
    	StudentHashCode stu1 = new StudentHashCode("10001", "赤骥");
    	StudentHashCode stu2 = new StudentHashCode("10001", "赤骥");
        StudentHashCode stu3 = new StudentHashCode("10002", "白义");

        Set<StudentHashCode> students = new HashSet<>();
        students.add(stu1);
        students.add(stu2);
        students.add(stu3);
        System.out.println(students.size());
    }
}
